<?php

class Account extends UsersBase
{
	public $verifyPassword;
	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules() {
		$rules = array(
			array('username, password', 'required'),
			array('username', 'length', 'max'=>20, 'min' => 3,'message' => "Tên nhập không đúng (phải từ 3 đến 20 kí tự)."),
			array('password', 'length', 'max'=>128, 'min' => 4,'message' => "Mật khẩu quá ngắn (ít nhất 3 kí tự)."),
			array('username', 'unique', 'message' => "Tài khoản này đã tồn tại."),

			//array('verifyPassword', 'compare', 'compareAttribute'=>'password', 'message' => UserModule::t("Retype Password is incorrect.")),
			array('username', 'match', 'pattern' => '/^[A-Za-z0-9_]+$/u','message' => "Tài khoản không được có kí tự đăc biệt"),
			array('status', 'in', 'range'=>array(STATUS_NOACTIVE, STATUS_ACTIVE)),
			array('id, username, create_at, lastvisit_at, status', 'safe', 'on'=>'search'),
		);
		return $rules;
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		return array_merge(parent::relations(),array(
			'member' => array(self::HAS_ONE, 'Member', 'user_id'),
		));
	}

	/**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria=new CDbCriteria;

        $criteria->compare('id',$this->id);
        $criteria->compare('username',$this->username,true);
        $criteria->compare('password',$this->password);
        $criteria->compare('email',$this->email,true);
        $criteria->compare('activkey',$this->activkey);
        $criteria->compare('create_at',$this->create_at);
        $criteria->compare('lastvisit_at',$this->lastvisit_at);
        $criteria->compare('superuser',$this->superuser);
        $criteria->compare('status',$this->status);

        return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
    }
}